from selenium.webdriver.common.by import By
from base.base_action import BaseAction


# 试题库页面
class QuestionBankPage(BaseAction):
    # 试卷与试题按钮
    papers_and_questions_btn = By.XPATH, "//span[text()='试题与试卷']"

    # 试题库按钮
    question_bank_btn = By.XPATH, "//span[text()='试题库']"

    # 题库名称搜索框
    course_name_search = By.XPATH, "//input[@placeholder='搜索题库']"

    # 时间筛选框
    time_filter = By.CSS_SELECTOR, "input.el-range-input:nth-child(2)"

    # 最近一周,最近一个月筛选按钮
    last_week_btn = By.CSS_SELECTOR, "button.el-picker-panel__shortcut:nth-child(1)"
    last_month_btn = By.CSS_SELECTOR, "button.el-picker-panel__shortcut:nth-child(2)"

    # 状态筛选框
    status_filter = By.XPATH, "//input[@placeholder='状态']"
    enable_btn = By.XPATH, "/html/body/div[2]/div[1]/div[1]/ul/li[1]/span"
    disable_btn = By.XPATH, "/html/body/div[2]/div[1]/div[1]/ul/li[2]/span"

    # 新建按钮
    new_btn = By.XPATH, "//span[contains(text(),'新增试题库')]"

    # 题库名称输入框
    question_bank_name_input = By.XPATH, "//input[@placeholder='请选择题库名称']"

    # 资源分类输入框
    sort_input = By.XPATH, "//input[@placeholder='请选择资源分类']"

    # 选择资源分类
    select_source_sort = "document.getElementsByClassName('el-radio__inner')[5].click();"

    # 空白区域
    blank_area = By.XPATH, "//div[3]/div[3]//div[2]/main//div[3]/div/div[1]/main/div[1]/div[6]/div/div[1]"

    # 确定按钮
    determine_btn = By.XPATH, "//span[text()='确 定']"

    # 第二个确定按钮
    determine5_btn = By.XPATH, "//span[contains(text(), '确定')]"

    # 新增试题按钮
    add_question_btn = By.XPATH, "//button/span[contains(text(),'新增试题')]"

    # 题目输入框
    subject_input = By.XPATH, "//div[3]/div[3]//div[2]//div[6]/div/div[2]//div[2]/div/div/" \
                              "div[1]/div/div[1]/div[1]/div[2]/div[1]/textarea"

    # 选项A
    optionA_input = By.XPATH, "//div[3]/div[3]/div/div[2]/main/div/div/div[6]/div/div[2]/" \
                              "div/div[2]/div/div/div[1]/div/div[1]/div[2]/div/div[1]/div[2]/div[1]/textarea"

    # 选项B
    optionB_input = By.XPATH, "//div[3]/div[3]/div/div[2]/main/div/div/div[6]/div/div[2]/div/" \
                              "div[2]/div/div/div[1]/div/div[1]/div[2]/div/div[2]/div[2]/div[1]/textarea"

    # 答案选项按钮
    answer_option = "document.getElementsByClassName('el-radio__inner')[0].click();"

    # 确定按钮
    determine1_btn = By.XPATH, "//div[3]/div[3]//div[2]/main//div[6]/div/div[3]//button[1]/span"

    # 禁用按钮
    disable1_btn = "document.getElementsByClassName('operate-style')[1].click();"

    # 删除按钮
    remove_btn = "document.getElementsByClassName('operate-style')[2].click();"

    # 禁用的确定按钮
    determine4_btn = By.XPATH, "//span[contains(text(),'确定')]"

    # 点击试题与试卷
    def click_papers_and_questions_btn(self):
        return self.click(self.papers_and_questions_btn)

    # 点击试题库
    def click_question_bank_btn(self):
        return self.click(self.question_bank_btn)

    # 点击课程名称搜索框
    def click_course_name_search(self):
        return self.click(self.course_name_search)

    # 输入课程名称
    def input_courses_name(self, content):
        return self.input(self.course_name_search, content)

    # 点击新增时间筛选框
    def click_time_filter(self):
        return self.click(self.time_filter)

    # 点击最近一周
    def click_last_week_btn(self):
        return self.click(self.last_week_btn)

    # 点击最近一个月
    def click_last_month_btn(self):
        return self.click(self.last_month_btn)

    # 点击状态进行筛选
    def click_status_filter(self):
        return self.click(self.status_filter)

    # 点击已启用
    def click_enable_btn(self):
        return self.click(self.enable_btn)

    # 点击已禁用
    def click_disable_btn(self):
        return self.click(self.disable_btn)

    # 点击新建按钮
    def click_new_btn(self):
        return self.click(self.new_btn)

    # 输入题库名称
    def input_question_bank_name(self, content):
        return self.input(self.question_bank_name_input, content)

    # 点击资源分类输入框
    def click_sort_input(self):
        return self.click(self.sort_input)

    # 选择资源分类
    def select_third_sort(self):
        return self.execute_js(self.select_source_sort)

    # 点击空白区域
    def click_blank_area(self):
        return self.click(self.blank_area)

    # 点击确定按钮
    def click_determine_btn(self):
        return self.click(self.determine_btn)

    # 再次点击弹窗的确定
    def click_determine5_btn(self):
        return self.click(self.determine5_btn)

    # 点击新增试题
    def click_single_choice_questions_btn(self):
        self.switch_window()
        return self.click(self.add_question_btn)

    # 输入题目
    def input_subject(self, content):
        return self.input(self.subject_input, content)

    # 输入选项A
    def input_option_a(self, content):
        return self.input(self.optionA_input, content)

    # 输入选项B
    def input_option_b(self, content):
        return self.input(self.optionB_input, content)

    # 选择答案
    def select_answer(self):
        return self.execute_js(self.answer_option)

    # 点击确定按钮
    def click_determine1_btn(self):
        return self.click(self.determine1_btn)

    # 点击禁用按钮
    def click_disable1_btn(self):
        return self.execute_js(self.disable1_btn)

    # 禁用弹窗的确定按钮
    def click_determine3_btn(self):
        return self.click(self.determine4_btn)

    # 点击删除试题
    def click_remove_btn(self):
        return self.execute_js(self.remove_btn)
